package com.briup.jd2511.jd2511_product_source.controller;

import com.briup.jd2511.jd2511_product_source.exception.ServiceException;
import com.briup.jd2511.jd2511_product_source.pojo.DiseaseRecord;
import com.briup.jd2511.jd2511_product_source.pojo.ManagerDisease;
import com.briup.jd2511.jd2511_product_source.result.Result;
import com.briup.jd2511.jd2511_product_source.service.DiseaseRecordService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "病症记录模块")
@RestController
@RequestMapping("/diseaseRecord")
public class DiseaseController {
    @Autowired
    private DiseaseRecordService diseaseRecordService;

    @GetMapping("/queryAllDisease")
    @Operation(summary = "查询所有病症")
    public Result queryAllDisease(){
        return Result.success(diseaseRecordService.findAllDisease());
    }

    @GetMapping
    @Operation(summary = "分页+条件查询病症记录")
    @Parameters(value = {
            @Parameter(name = "pageName",description = "页码"),
            @Parameter(name = "pageSize",description = "每页数量"),
            @Parameter(name = "drStatus",description = "病症状态:未治疗|治疗中|已治疗 "),
            @Parameter(name = "drDId",description = "病症id")
    })
    public Result getAllByConditionByPage(@RequestParam(defaultValue = "1") Integer pageName,
                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                          @RequestParam(required = false) String drStatus,
                                          @RequestParam (required = false) String drDId){
        PageInfo<ManagerDisease> pageInfo = diseaseRecordService.findByPage(pageName,pageSize,drStatus,drDId);
        return Result.success(pageInfo);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "添加/修改病症记录")
    @Parameters(value = {
            @Parameter(name = "drId",description = "病症id"),
            @Parameter(name = "drAnimalId",description = "动物编号"),
            @Parameter(name = "drDesc",description = "处理描述"),
            @Parameter(name = "drCure",description = "处理方案"),
            @Parameter(name = "drTime",description = "处理时间"),
            @Parameter(name = "drStatus",description = "病症状态:未治疗|治疗中|已治疗"),
            @Parameter(name = "drDId",description = "病症id")
    })
    public Result saveOrUpdate(@RequestBody DiseaseRecord diseaseRecord){
        try {
            diseaseRecordService.saveOrUpdate(diseaseRecord);
            return Result.success();
        } catch (ServiceException e) {
            return Result.failure(e.getResultCode());
        }
    }

}
